package com.aft.terra.modules.game.model;

import com.aft.terra.common.utils.DateUtil;
import com.aft.terra.modules.game.model.base.BaseShareUser;
import com.jfinal.plugin.activerecord.Db;

public class ShareUser extends BaseShareUser<ShareUser> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final ShareUser dao = new ShareUser();
	
	public Integer findByCount(String state,String startDate ,String endDate) {
		String sql = new StringBuffer()
				.append("select count(*) from t_share_user where share_user_id = ? ")
				.append("and create_date between ")
				.append(startDate)
				.append(" and ")
				.append(endDate).toString();
		
		return Db.queryLong(sql,state).intValue();
	}

	public ShareUser findByUserId(String userId) {
		String sql ="select * from t_share_user where user_id = ? and type=0";
		return findFirst(sql,userId);
	}

	public boolean findByShareUserId(Long shareUserId) {
		StringBuffer sql =new StringBuffer();
		sql.append("select count(*) from t_share_user where share_user_id = ? and type=1")
		.append(" and modify_date between ")
		.append(DateUtil.nowDateBegin())
		.append(" and ")
		.append(DateUtil.nowDateEnd());
		
		return Db.queryLong(sql.toString(),shareUserId).intValue() < 3;
	}
}
